package com.wxq.common.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {

    private Set<Integer> integers = new HashSet<>();

    /**
     * 动态代理反射注解类获取参数
     * @param constraintAnnotation
     */
    @Override
    public void initialize(ListValue constraintAnnotation) {
        for (int value : constraintAnnotation.value()) {
            integers.add(value);
        }
 // b        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    /**
     * 教研参数
     * @param integer
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return integers.contains(integer);
    }
}
